package cn.edu.sdu.sol.intake_system.repository;

import cn.edu.sdu.sol.intake_system.model.po.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<SysUser, Integer> {
    @Query(value = "SELECT * FROM sys_user WHERE student_num = ?1", nativeQuery = true)
    Optional<SysUser> findUserByStudentNum(String studentNum);

    @Query(value = "from SysUser where personInf.personInfPk=?1")
    Optional<SysUser> findUserByPersonId(Integer personId);

    @Query(value = "from SysUser where role = 0")
    List<SysUser> findAdmin();

    @Query(value = "from SysUser where userPk=?1")
    Optional<SysUser> findUserByUserPk(Integer userPk);
}
